/*
 * Copyright (c) 2010 Mathias Garbe <code@mathias-garbe.de>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#ifndef MAIN_HPP
#define MAIN_HPP

#define CURL_STATICLIB

#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <windows.h>
#include <commctrl.h>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <stdexcept>
#include <process.h>
#include <gdiplus.h>
#include <comdef.h>
#include <comdefsp.h>
#include <exdisp.h>
#include <Mshtml.h>
#include <atlbase.h>
#include <Shellapi.h>

#include <vector>

#include <curl/curl.h>

namespace WinAPI
{
	static HINSTANCE hInstance(HINSTANCE hInstance = 0)
	{
		static HINSTANCE i;
		if(hInstance != 0)
			i = hInstance;
		return i;
	}

	// Returns path to the exe with filename appended
	static std::string getFullPath()
	{
		LPCH tmpExePath = new TCHAR[_MAX_PATH];
		::GetModuleFileName((HINSTANCE)WinAPI::hInstance(), tmpExePath, _MAX_PATH);
		std::string fullPath = tmpExePath;

		return fullPath;
	}

	// Returns path to the exe without filename
	static std::string getPath()
	{
		if(WinAPI::getFullPath().find_last_of("\\") == std::string::npos)
		{
			return "";
		}

		std::string exePath = WinAPI::getFullPath().substr(0, WinAPI::getFullPath().find_last_of("\\"));
		return exePath;
	}

	static int desktopWidth()
	{
		return GetSystemMetrics(SM_CXSCREEN);
	}

	static int desktopHeight()
	{
		return GetSystemMetrics(SM_CYSCREEN);
	}
}

namespace std
{
	std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems);

	std::vector<std::string> split(const std::string &s, char delim);

}

bool FileExists(const char *path);


#include "Update.hpp"

#endif
